auto.waitFor();
 function 随机数(minNum,maxNum) {
 
  switch(arguments.length){ 
      case 1: 
          return parseInt(Math.random()*minNum+1,10); 
      break; 
      case 2: 
          return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
      break; 
          default: 
              return 0; 
          break; 
  } 

}


评论数组=global.WEB_PARAMS.comment.split('\n')
console.log(global.WEB_PARAMS)
var Max = 10;
t1=new Date().getTime()
t4=new Date().getTime()
启动抖音()
for (;;) {
  t2=new Date().getTime()
  t3=new Date().getTime()
  if ((t3-t4)>20*1000){
log('超时')
back()
sleep(3000);
back()
sleep(3000);

t4=new Date().getTime()
  }
  log(t2-t1)
  if ((t2-t1)>global.WEB_PARAMS.interval*60*1000){
   break
  }
  swipeUp();
sleep(随机数(5000,10000))
  sleep(2000);
  try{

 
  if (text('点击进入直播间').exists()) {
    t4=new Date().getTime()
    continue;
  }
  if (text('点击观看直播').exists()) {
    t4=new Date().getTime()
    continue;
  }
  if (text('广告').exists()) {
    t4=new Date().getTime()
    continue;
  }
 if ( like()){
  t4=new Date().getTime()
  log('已点赞')
  continue;
 }
 if ( subscribe()){
  t4=new Date().getTime()
  log('已关注')
  continue;
 }
 if ( comment()){
  t4=new Date().getTime()
  log('已评论')
  continue;
 } }catch(e)
 {
  log(e)
 }

 sleep(随机数(1000,5000))
    if (!text('推荐').exists()){
      log('不在首页')
      back()
      sleep(3000);
      back()
      sleep(3000);
      t4=new Date().getTime()
    }
    if (packageName('com.ss.android.ugc.aweme').exists()==false){
      log('抖音闪退')
      启动抖音()
      t4=new Date().getTime()
  }
}
toastLog('任务完成')
//点赞

function like () {
  try{
    var likeBtn = descContains('喜欢').visibleToUser().findOnce()

    if (Math.random()<global.WEB_PARAMS.zanMax){
  
      likeBtn.click()
      sleep(2000);
      return true
    }
  }catch(e){
    log('点赞出错')
    sleep(2000);
    back()
  }

return false
}
//关注
function subscribe(){
  try{
  var subscribeBtn=descContains('关注').visibleToUser().findOnce()
  if (Math.random()<global.WEB_PARAMS.subscribeMax){
    subscribeBtn.click()
    sleep(2000);
    return true
  }
}catch(e){
  log('关注')
  sleep(2000);
  back()
}
  return false
}
function comment(){
  try{
  var commentBtn=descContains('评论').visibleToUser().findOnce()
  if (Math.random()<global.WEB_PARAMS.commentMax){
    log('开始评论')
    commentBtn.click()
    sleep(2000);
    setText(评论数组[随机数(0,评论数组.length-1)] )
    sleep(2000);
    // a2 = text("发送").findOnce().bounds().centerX();
    // a3 = text("发送").findOnce().bounds().centerY();
    // log(a2,a3)
    // press(a2, a3, 1)   //press(x,y,1)
    // sleep(800)
    press(966,1952,1)  
    sleep(2000);
   back()
   sleep(2000);
    return true
  }
}catch(e){
  log(e)
  log('评论出错')
sleep(2000);
exit()
back()
}
  return false
}